package com.careerraiser.testing;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.careerraiser.child.Cat;
import com.careerraiser.child.Dog;
import com.careerraiser.parent.Animal;

public class MapTest {

	public static void main(String[] args) {
		Map<String,Animal> testMap=new HashMap<String,Animal>();
        testMap.put("Animal1", new Dog("dog1"));
        testMap.put("Animal2", new Cat());
        testMap.put("Animal3", new Dog("dog3"));
        //while taking out values, key should be exact.
        //otherwise it will return null.
        System.out.println(testMap.get("dog3"));
        
        Set<Entry<String,Animal>> eList=testMap.entrySet();
       System.out.println("Printing all the key and values in map");
        for (Entry<String, Animal> entry : eList) {
			System.out.println(entry.getKey()+":"+entry.getValue());
		}
        
        //getting the set ofkeys in the map als printing those
        System.out.println("printing all the keys");
        Set<String> kSet=testMap.keySet();
        for (String string : kSet) {
			System.out.println(string);
		}
        
        //getting a list of values from map
        System.out.println("printing all values");
       Collection<Animal> anmColl= testMap.values();
		for (Animal animal : anmColl) {
			System.out.println(animal);
		}
		
		Iterator<Animal> itr2=anmColl.iterator();
		while (itr2.hasNext()){
			Animal an2=itr2.next();
			itr2.remove();
		}
		//since we removed the first element. the code below may print null.
		System.out.println(testMap.get("Animal2"));
	}

}
